package cn.z2huo.knowledge.basic.arrays.arraysclass.parallel;

import java.util.Arrays;

/**
 * <p>
 *
 * @author z2huo
 */
public class ParallelInitTest {

    public static void main(String[] args) {
        int size = 1_000_000_000;
        long start, end;

        start = System.currentTimeMillis();
        double[] doubles = imperativeInitilize(size);
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        double[] doubles2 = parallelInitialize(size);
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static double[] imperativeInitilize(int size) {
        double[] values=new double[size];
        for(int i=0; i < values.length; i++) {
            values[i]=i;
        }
        return values;
    }

    public static double[] parallelInitialize(int size) {
        double[] values=new double[size];
        Arrays.parallelSetAll(values, i-> i);
        return values;
    }

}
